
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_ahj_app/app/feedback/viewModel/feedbackViewModel.dart';
import 'package:flutter_ahj_app/base/basewidget/view/BaseWidget.dart';
import 'package:flutter_ahj_app/base/utils/JUIKit/JFlatButton.dart';
import 'package:flutter_ahj_app/base/utils/JUIKit/JPCH.dart';
import 'package:flutter_ahj_app/base/utils/JUIKit/JText.dart';
import 'package:flutter_ahj_app/base/utils/ToastUtils.dart';
import 'package:flutter_ahj_app/base/utils/mTopBar.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';

class FeedbackView extends BaseStatefulWidget{
  @override
  State<StatefulWidget> initState() {
    // TODO: implement initState
    return _FeedbackViewState();
  }


}

class _FeedbackViewState extends BaseState<FeedbackViewModel, FeedbackView>{




  TextEditingController _contactInformation = TextEditingController();///联系方式

  TextEditingController _suggestions = TextEditingController();///意见建议



  @override
  Widget initWidget() {
    // TODO: implement initWidget
    return Scaffold(
      appBar: MTopBar(title: "产品反馈",
        rightButtonText: "提交",
        onRightButtonClick: () => _saveAction(),

      ).create(),
      body: _bodyView(),
    );
  }

  _bodyView() {

    return Padding(
      padding: const EdgeInsets.fromLTRB(15, 10, 15, 0),
      child: GestureDetector(
          onTap: ()=> _dismissKeyBoard() ,
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              JText("您的联系方式"),
              TextField(
                controller: _contactInformation,
                keyboardType: TextInputType.number,
                decoration: InputDecoration(
//                    contentPadding: EdgeInsets.all(15.0),
                      hintText: "请输入",
                      hintStyle: TextStyle(fontSize: Dimens.dimens15,color: SQColor.per28Black),
//                    border: OutlineInputBorder(
//
//                    ),
                ),
              ),

              Padding(
                padding: const EdgeInsets.fromLTRB(0, 15, 0, 10),
                child: JText("意见/建议"),
              ),
              TextField(
                controller: _suggestions,
                maxLines: 10,
                maxLength: 200,
                maxLengthEnforced: true,
                decoration: InputDecoration(
                  hintText: "请写下您使用App时遇到的问题或您对本产品的建议，感谢支持。",
                    hintStyle: TextStyle(fontSize: Dimens.dimens15,color: SQColor.per28Black),
                    contentPadding: EdgeInsets.all(15.0),
                    border: OutlineInputBorder(),
                ),
//
              ),
            ],
          ),
        ),
      ),
    );

  }
  ///保存事件
  _saveAction() {
    if(_judgeEmpty()==true) return;

    viewModel.getData(content: _suggestions.text,username: _contactInformation.text);

    Stream dataStream = viewModel.dataStream();
    dataStream.listen((result){

      print("反馈信息"+result);

      ToastUtils.showToast(result??"返回出错");

      Future.delayed(Duration(seconds: 1),()=>Navigator.pop(context));

    });
  }
  ///判断有没填写
 bool _judgeEmpty() {

    if(_contactInformation.text==""){
      ToastUtils.showToast("请填写您的联系方式");
      return true;
    }
    if(_suggestions.text==""){
      ToastUtils.showToast("请填写您的反馈建议");
      return true;
    }

    return false;
  }
  /// 键盘失去 焦点
  _dismissKeyBoard() {
    FocusScope.of(context).requestFocus(FocusNode());
  }
}